package com.xoa.service.party;


import com.xoa.dao.common.SysCodeMapper;
import com.xoa.dao.party.*;
import com.xoa.model.common.SysCode;
import com.xoa.model.party.*;
import com.xoa.model.users.Users;
import com.xoa.util.DateFormat;
import com.xoa.util.ExcelUtil;
import com.xoa.util.GetAttachmentListUtil;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.log.FileUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.common.wrapper.BaseWrappers;
import com.xoa.util.page.PageParams;
import org.apache.commons.collections4.map.HashedMap;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.NumberFormat;
import java.util.*;

@Service
public class FixFormService {

    @Autowired
    private GeneralSafetyUnitMapper generalSafetyUnitMapper;//第一个
    @Autowired
    private SmallScaleSecurityUnitMapper smallScaleSecurityUnitMapper; //第二个
    @Autowired
    private ThreeFormMapper threeFormMapper;//第三个
    @Autowired
    private FourFormMapper fourFormMapper;//第四个
    @Autowired
    private FixFormMapper fixFormMapper;//第五个
    @Autowired
    private SysCodeMapper sysCodeMapper;


    public BaseWrapper insertSelective(FixFormWithBLOBs fixForm) {

        BaseWrapper baseWrappers = new BaseWrapper();

        int a = fixFormMapper.insertSelective(fixForm);
        if (a > 0) {
            baseWrappers.setMsg("ok");
            baseWrappers.setData(fixForm);
            baseWrappers.setFlag(true);

        } else {
            baseWrappers.setMsg("err");

            baseWrappers.setFlag(false);
        }

        return baseWrappers;
    }

    public BaseWrapper updateByPrimaryKeySelective(FixFormWithBLOBs fixForm) {
        BaseWrapper baseWrappers = new BaseWrapper();
        int a = fixFormMapper.updateByExampleSelective(fixForm);
        if (a > 0) {
            baseWrappers.setMsg("ok");
            baseWrappers.setData(fixForm);
            baseWrappers.setFlag(true);
        } else {
            baseWrappers.setMsg("err");
            baseWrappers.setFlag(false);
        }
        return baseWrappers;
    }

    public BaseWrapper selectByFixFromId(Integer fixFromId, HttpServletRequest request) {
        BaseWrapper baseWrappers = new BaseWrapper();
        FixFormWithBLOBs fixFormWithBLOBs = fixFormMapper.selectByFixFromId(fixFromId);

        baseWrappers.setMsg("ok");
        baseWrappers.setData(fixFormWithBLOBs);
        baseWrappers.setFlag(true);
        return baseWrappers;
    }

    public BaseWrapper deleteByExample(Integer fixFromId) {
        BaseWrapper baseWrappers = new BaseWrapper();
        int a = fixFormMapper.deleteByExample(fixFromId);
        if (a > 0) {
            baseWrappers.setMsg("ok");
            baseWrappers.setFlag(true);
        } else {
            baseWrappers.setMsg("err");
            baseWrappers.setFlag(false);
        }
        return baseWrappers;
    }


    public BaseWrappers selectList(HttpServletRequest request, Integer page, Integer pageSize, Boolean userFlag) {
        BaseWrappers baseWrappers = new BaseWrappers();
        Map<String, Object> objectMap = new HashMap<String, Object>();
        PageParams pageParams = new PageParams();
        pageParams.setUseFlag(userFlag);
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        objectMap.put("page", pageParams);
        List<FixFormWithBLOBs> fixFormWithBLOBs = fixFormMapper.seleteByList(objectMap);
        baseWrappers.setDatas(fixFormWithBLOBs);
        baseWrappers.setTotal(pageParams.getTotal());
        baseWrappers.setMsg("ok");
        baseWrappers.setFlag(true);
        baseWrappers.setStatus(true);
        return baseWrappers;
    }

    private final static int ONEFORM_ID = 1;
    private final static int TWOFORM_ID = 2;
    private final static int THREEFORM_ID = 3;
    private final static int FOURFORM_ID = 4;
    private final static int FIVRFORM_ID = 5;

    public BaseWrappers selectFormList(HttpServletRequest request, Integer page, Integer pageSize, Boolean userFlag, String type, String code, String gridCode) {
        BaseWrappers baseWrappers = new BaseWrappers();
        Map<String, Object> objectMap = new HashMap<String, Object>();
        PageParams pageParams = new PageParams();
        pageParams.setUseFlag(userFlag);
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        objectMap.put("page", pageParams);
        objectMap.put("code", code);
        objectMap.put("gridCode",gridCode);
        switch (Integer.valueOf(type)) {
            case ONEFORM_ID:
                List<GeneralSafetyUnitWithBLOBs> list1 = generalSafetyUnitMapper.selectSelective(objectMap);
                baseWrappers.setDatas(list1);
                break;
            case TWOFORM_ID:

                List<SmallScaleSecurityUnitWithBLOBs> list = smallScaleSecurityUnitMapper.selectSelective(objectMap);
                baseWrappers.setDatas(list);
                break;
            case THREEFORM_ID:
                List<ThreeForm> list2 = threeFormMapper.query(objectMap);
                baseWrappers.setDatas(list2);
                break;
            case FOURFORM_ID:
                List<FourFormWithBLOBs> list3 = fourFormMapper.query(objectMap);
                baseWrappers.setDatas(list3);
                break;
            case FIVRFORM_ID:
                List<FixFormWithBLOBs> fixFormWithBLOBs = fixFormMapper.seleteByList(objectMap);
                baseWrappers.setDatas(fixFormWithBLOBs);
                break;
        }
        baseWrappers.setTotal(pageParams.getTotal());
        baseWrappers.setFlag(true);
        baseWrappers.setMsg("ok");
        return baseWrappers;
    }


    public BaseWrapper selectByListFixFromId(Integer fixFromId, HttpServletRequest request, String type) {
        BaseWrapper baseWrappers = new BaseWrapper();
        String sqlType = "xoa"
                + (String) request.getSession().getAttribute("loginDateSouse");
        switch (Integer.valueOf(type)) {
            case ONEFORM_ID:
                GeneralSafetyUnitWithBLOBs gen = generalSafetyUnitMapper.selectByPrimaryKey(fixFromId);
                if (gen.getAttachmentName() != null && gen.getAttachmentId() != null) {
                    gen.setAttachment(GetAttachmentListUtil.returnAttachment(gen.getAttachmentName(), gen.getAttachmentId(), sqlType, GetAttachmentListUtil.MODULE_grid));
                }
                baseWrappers.setData(gen);
                break;
            case TWOFORM_ID:

                SmallScaleSecurityUnitWithBLOBs small = smallScaleSecurityUnitMapper.selectByPrimaryKey(fixFromId);
                if (small.getAttachmentName() != null && small.getAttachmentId() != null) {
                    small.setAttachment(GetAttachmentListUtil.returnAttachment(small.getAttachmentName(), small.getAttachmentId(), sqlType, GetAttachmentListUtil.MODULE_grid));
                }
                baseWrappers.setData(small);
                break;
            case THREEFORM_ID:
                ThreeForm three = threeFormMapper.selectByPrimaryKey(fixFromId);
                if (three.getCertAttachName() != null && three.getCertAttachId() != null) {
                    three.setAttachment(GetAttachmentListUtil.returnAttachment(three.getCertAttachName(), three.getCertAttachId(), sqlType, GetAttachmentListUtil.MODULE_grid));
                }
                if(three.getOpenTime()!=null){
                    three.setBeginTime(DateFormat.getStrDate(three.getOpenTime()));
                }
                baseWrappers.setData(three);
                break;
            case FOURFORM_ID:
                FourForm list3 = fourFormMapper.selectByPrimaryKey(fixFromId);
                if (list3.getCertAttachName() != null && list3.getCertAttachId() != null) {
                    list3.setAttachment(GetAttachmentListUtil.returnAttachment(list3.getCertAttachName(), list3.getCertAttachId(), sqlType, GetAttachmentListUtil.MODULE_grid));
                }
                if(list3.getOpenTime()!=null){
                    list3.setBeginTime(DateFormat.getStrDate(list3.getOpenTime()));
                }
                baseWrappers.setData(list3);
                break;
            case FIVRFORM_ID:
                FixFormWithBLOBs fixFormWithBLOBs = fixFormMapper.selectByFixFromId(fixFromId);
                if (fixFormWithBLOBs.getAttachmentName() != null && fixFormWithBLOBs.getAttachmentId() != null) {
                    fixFormWithBLOBs.setAttachment(GetAttachmentListUtil.returnAttachment(fixFormWithBLOBs.getAttachmentName(), fixFormWithBLOBs.getAttachmentId(), sqlType, GetAttachmentListUtil.MODULE_grid));
                }
                //处理位置信息
               SysCode sysCode= sysCodeMapper.getSingleCode("TYPE_OF_ACCOUNT",fixFormWithBLOBs.getGridCode());
                fixFormWithBLOBs.setGridName(sysCode.getCodeName());
                baseWrappers.setData(fixFormWithBLOBs);
                break;
        }
        baseWrappers.setFlag(true);
        baseWrappers.setMsg("ok");
        return baseWrappers;
    }

    public BaseWrapper deleteByExamplebyId(Integer fixFromId, Integer type) {
        BaseWrapper baseWrappers = new BaseWrapper();

        switch (Integer.valueOf(type)) {
            case ONEFORM_ID:
                int a1 =  generalSafetyUnitMapper.deleteByPrimaryKey(fixFromId);
                if (a1> 0) {
                    baseWrappers.setMsg("ok");
                    baseWrappers.setFlag(true);
                }

                break;
            case TWOFORM_ID:

                int a2 =  smallScaleSecurityUnitMapper.deleteByPrimaryKey(fixFromId);
                if (a2> 0) {
                    baseWrappers.setMsg("ok");
                    baseWrappers.setFlag(true);
                }

                break;
            case THREEFORM_ID:
                int a3 =  threeFormMapper.deleteByPrimaryKey(fixFromId);
                if (a3 > 0) {
                    baseWrappers.setMsg("ok");
                    baseWrappers.setFlag(true);
                }

                break;
            case FOURFORM_ID:
                int a4 = fourFormMapper.deleteByPrimaryKey(fixFromId);
                if (a4 > 0) {
                    baseWrappers.setMsg("ok");
                    baseWrappers.setFlag(true);
                }
                break;
            case FIVRFORM_ID:
                int a5 = fixFormMapper.deleteByExample(fixFromId);
                if (a5 > 0) {
                    baseWrappers.setMsg("ok");
                    baseWrappers.setFlag(true);
                }
                break;
        }
        baseWrappers.setFlag(true);
        baseWrappers.setMsg("ok");
        return baseWrappers;
    }

    public BaseWrappers selectUnionAll(HttpServletRequest request, String  itemType){

        BaseWrappers baseWrappers = new BaseWrappers();
        List<FixFormWithBLOBs> fix = fixFormMapper.selectUnionAll(itemType);
        baseWrappers.setFlag(true);
        baseWrappers.setMsg("ok");
        baseWrappers.setDatas(fix);
        return  baseWrappers;
    }
    public BaseWrappers selectUnionAllType(HttpServletRequest request, String  itemType){

        BaseWrappers baseWrappers = new BaseWrappers();
        List<FixFormWithBLOBs> fix = fixFormMapper.selectUnionAllType(itemType);
        baseWrappers.setFlag(true);
        baseWrappers.setMsg("ok");
        baseWrappers.setDatas(fix);
        return  baseWrappers;
    }




    public BaseWrappers selectUnionAllByname(HttpServletRequest request, HttpServletResponse response, String unitName, Integer page, Integer pageSize, Boolean userFlag, String orgName, String codeType, String area,
                                             String  number, String beginDate, String endDate, String businesSstuts, String dangerous, Integer daochu){
        BaseWrappers baseWrappers = new BaseWrappers();
        Map<String,Object> paMap=new HashMap<String,Object>();
        PageParams pageParams = new PageParams();
        pageParams.setUseFlag(userFlag);
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        paMap.put("unitName",unitName);
        paMap.put("orgName",orgName);
        paMap.put("codeType",codeType);
        paMap.put("area",area);
        paMap.put("number",number);
        paMap.put("beginDate",beginDate);
        paMap.put("endDate",endDate);
        paMap.put("businesSstuts",businesSstuts);
        paMap.put("dangerous",dangerous);
        paMap.put("page",pageParams);
      if(!StringUtils.checkNull(area)&&!StringUtils.checkNull(dangerous)){
          paMap.put("fxbiaozhi","2");
     }
        List<FixFormWithBLOBs> fix= fixFormMapper.selectUnionAllByname(paMap);
        String sqlType = "xoa"
                + (String) request.getSession().getAttribute("loginDateSouse");
        //判断是否导出 1为导出操作
        if(daochu!=null){
                List<GridFileOutPutModel> gridlist=new ArrayList<GridFileOutPutModel>();
                for(int i=0;i<fix.size();i++){
                String zhujian = fix.get(i).getZhujian();
                String biaozhi = fix.get(i).getBiaozhi();

                if(Integer.parseInt(biaozhi)==1){  //一般安全生产法人单位
                    GeneralSafetyUnitWithBLOBs gen = generalSafetyUnitMapper.selectByPrimaryKey(Integer.parseInt(zhujian));
                    GridFileOutPutModel filemmodel=new GridFileOutPutModel();
                    filemmodel.setId(i+1);
                    filemmodel.setBussinesscode(gen.getBusinessRegistrationNo()==null?"":gen.getBusinessRegistrationNo());
                    filemmodel.setFormType(Integer.parseInt(biaozhi));
                    filemmodel.setManagername(gen.getLegalRepresentative());
                    filemmodel.setManagerphone(gen.getMobilePhone());
                    filemmodel.setProductname(gen.getUnitName());
                    filemmodel.setProductaddress(gen.getUnitLocationArea());
                    filemmodel.setRegisteraddress(gen.getUndergroundArea());
                    gridlist.add(filemmodel);
                }else if(Integer.parseInt(biaozhi)==2){ //小规模安全生产法人单位
                    SmallScaleSecurityUnitWithBLOBs small = smallScaleSecurityUnitMapper.selectByPrimaryKey(Integer.parseInt(zhujian));
                    GridFileOutPutModel filemmodel2=new GridFileOutPutModel();
                    filemmodel2.setId(i+1);
                    filemmodel2.setBussinesscode(small.getBusinessRegistrationNo()==null?"":small.getBusinessRegistrationNo());
                    filemmodel2.setFormType(Integer.parseInt(biaozhi));
                    filemmodel2.setManagername(small.getLegalRepresentative());
                    filemmodel2.setManagerphone(small.getMobilePhone());
                    filemmodel2.setProductname(small.getUnitName());
                    filemmodel2.setProductaddress(small.getUnitLocationArea());
                    filemmodel2.setRegisteraddress(small.getUndergroundArea());
                    gridlist.add(filemmodel2);
                }else if(Integer.parseInt(biaozhi)==3){ //大型安全生产个体工商户基础信息
                    ThreeForm three = threeFormMapper.selectByPrimaryKey(Integer.parseInt(zhujian));
                    GridFileOutPutModel filemmodel2=new GridFileOutPutModel();
                    filemmodel2.setId(i+1);
                    filemmodel2.setBussinesscode(three.getBsLicenseRegist()==null?"":three.getBsLicenseRegist());
                    filemmodel2.setFormType(Integer.parseInt(biaozhi));
                    filemmodel2.setManagername(three.getLightnDetect());
                    filemmodel2.setManagerphone(three.getMobPh());
                    filemmodel2.setProductname(three.getOpName());
                    filemmodel2.setProductaddress(three.getPrAddress());
                    filemmodel2.setRegisteraddress(three.getPrAddress());
                    gridlist.add(filemmodel2);

                }else if(Integer.parseInt(biaozhi)==4){  //小型安全生产个体工商户基础信息
                    FourForm list3 = fourFormMapper.selectByPrimaryKey(Integer.parseInt(zhujian));
                    GridFileOutPutModel filemmodel2=new GridFileOutPutModel();
                    filemmodel2.setId(i+1);
                    filemmodel2.setBussinesscode(list3.getBsLicenseRegist()==null?"":list3.getBsLicenseRegist());
                    filemmodel2.setFormType(Integer.parseInt(biaozhi));
                    filemmodel2.setManagername(list3.getLightnDetect());
                    filemmodel2.setManagerphone(list3.getMobPh());
                    filemmodel2.setProductname(list3.getOpName());
                    filemmodel2.setProductaddress(list3.getPrAddress());
                    filemmodel2.setRegisteraddress(list3.getPrAddress());
                    gridlist.add(filemmodel2);

                }else{    //在建工程项目基础信息
                    FixFormWithBLOBs fixFormWithBLOBs = fixFormMapper.selectByFixFromId(Integer.parseInt(zhujian));
                    GridFileOutPutModel filemmodel2=new GridFileOutPutModel();
                    filemmodel2.setId(i+1);
                    filemmodel2.setFormType(Integer.parseInt(biaozhi));
                    filemmodel2.setProductname(fixFormWithBLOBs.getItemName());
                    gridlist.add(filemmodel2);
                }

            }
            try{
                HSSFWorkbook workbook1 = ExcelUtil.makeExcelHead("企业信息", 9);
                String[] secondTitles = {"序号","企业类型","生产经营单位名称","生产经营地址","企业负责人姓名","企业负责人手机","注册地址","法人名称","法人电话","社会统一信用代码","企业工商注册号","组织机构代码","国民经济类型","监管行业分类","是否涉及危险化学品","职业危害因素","是否涉及有限空间作业","有无燃气或液化石油气场所","安全生产标准化评审等级"};
                HSSFWorkbook workbook2 = ExcelUtil.makeSecondHead(workbook1, secondTitles);

                // String[] beanProperty = {user.getDep().getDeptName(),"userName","userPrivName", "roleAuxiliaryName","online","sex","online","telNoDept","telNoDept","departmentPhone","email"};
                String[] beanProperty = {"id","formType","productname", "productaddress", "managername", "managerphone", "registeraddress", "farenname", "farenphone", "socialcode", "bussinesscode", "organizacode", "economictype", "supervicetype", "chemicalproduct", "dangrous", "spatialtask", "gasitem", "securitylevel"};

                HSSFWorkbook workbook = ExcelUtil.exportExcelData(workbook2,gridlist, beanProperty);
                ServletOutputStream out = response.getOutputStream();

                String filename = "bussinessinfo.xls";
                filename = FileUtils.encodeDownloadFilename(filename,
                        request.getHeader("user-agent"));
                response.setContentType("application/vnd.ms-excel");
                response.setHeader("content-disposition",
                        "attachment;filename=" + filename);
                workbook.write(out);
                out.flush();
                out.close();
                baseWrappers.setFlag(true);
                baseWrappers.setMsg("ok");
                return  baseWrappers;
            }catch(Exception e){
                e.printStackTrace();
            }
        }
        baseWrappers.setFlag(true);
        baseWrappers.setMsg("ok");
        baseWrappers.setTotal(pageParams.getTotal());
        baseWrappers.setDatas(fix);

        return  baseWrappers;
    }

    public BaseWrapper selectCounts(){
        BaseWrapper baseWrappers = new BaseWrapper();
        try {
            FixFormWithBLOBs fixFormWithBLOBs = fixFormMapper.selectCounts();
            baseWrappers.setData(fixFormWithBLOBs);
            baseWrappers.setFlag(true);
            baseWrappers.setMsg("ok");
            baseWrappers.setStatus(true);
        } catch (Exception e) {
            baseWrappers.setFlag(false);
            baseWrappers.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return baseWrappers;
    }

   public BaseWrapper selectTypeCount(){
        BaseWrapper baseWrappers = new BaseWrapper();
        try {
            FixFormWithBLOBs fixFormWithBLOBs = fixFormMapper.selectTypeCount();
            baseWrappers.setData(fixFormWithBLOBs);
            baseWrappers.setFlag(true);
            baseWrappers.setMsg("ok");
        }catch (Exception e){
            baseWrappers.setFlag(false);
            baseWrappers.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return baseWrappers;
   }

    public BaseWrappers selectCountByTypeId(String typeId){
        BaseWrappers baseWrappers = new BaseWrappers();

        try {
             Map<String,Object> map =new HashedMap();
            if(!StringUtils.checkNull(typeId)){
                map.put("typeId",typeId);
            }
            List<FourFormWithBLOBs> fourFormWithBLOBs = fourFormMapper.selectCountByTypeId(map);
            FourFormWithBLOBs fourFormWithBLOBs1 = fourFormMapper.selectSumCountById(map);
            baseWrappers.setTotal(Integer.valueOf(fourFormWithBLOBs1.getSumcount()));
            baseWrappers.setDatas(fourFormWithBLOBs);
            baseWrappers.setFlag(true);
            baseWrappers.setMsg("ok");
            baseWrappers.setStatus(true);
        } catch (Exception e) {
            baseWrappers.setFlag(false);
            baseWrappers.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return baseWrappers;
    }


    public BaseWrapper selectFlowCounts(){
        BaseWrapper baseWrappers = new BaseWrapper();
        try {
            FixFormWithBLOBs fixFormWithBLOBs = fixFormMapper.selectFlowCounts();

            NumberFormat numberFormat = NumberFormat.getInstance();

            // 设置精确到小数点后2位

            numberFormat.setMaximumFractionDigits(2);

            String result = numberFormat.format((float) Float.valueOf(fixFormWithBLOBs.getNum1()) / Float.valueOf(fixFormWithBLOBs.getSum()) * 100);
            String result1 = numberFormat.format((float) Float.valueOf(fixFormWithBLOBs.getNum2()) / Float.valueOf(fixFormWithBLOBs.getSum()) * 100);
            fixFormWithBLOBs.setNum1Percent(result);
            fixFormWithBLOBs.setNum2Percent(result1);
            baseWrappers.setData(fixFormWithBLOBs);
            baseWrappers.setFlag(true);
            baseWrappers.setMsg("ok");
            baseWrappers.setStatus(true);
        } catch (Exception e) {
            baseWrappers.setFlag(false);
            baseWrappers.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return baseWrappers;
    }
    /**
     * @Author  程叶同
     * @date    15:10 2017-12-29
     * @Desc    批量删除
     * @param
     **/
    public BaseWrapper deleteByIds(String ids, Integer typeId){
        String[] array=null;
        BaseWrapper baseWrapper=new BaseWrapper();
        if(ids!=null){
            array=ids.split(",");
            switch (typeId){
                case 1:
                    for(String id:array){
                        generalSafetyUnitMapper.deleteByPrimaryKey(Integer.parseInt(id));
                    }
                    baseWrapper.setMsg("ok");
                    baseWrapper.setFlag(true);
                    baseWrapper.setTime(new Date());
                    break;
                case 2:
                    for(String id:array){
                        smallScaleSecurityUnitMapper.deleteByPrimaryKey(Integer.parseInt(id));
                    }
                    baseWrapper.setMsg("ok");
                    baseWrapper.setFlag(true);
                    baseWrapper.setTime(new Date());
                    break;
                case 3:
                    for(String id:array){
                        threeFormMapper.deleteByPrimaryKey(Integer.parseInt(id));
                    }
                    baseWrapper.setMsg("ok");
                    baseWrapper.setFlag(true);
                    baseWrapper.setTime(new Date());
                    break;
                case 4:
                    for(String id:array){
                        fourFormMapper.deleteByPrimaryKey(Integer.parseInt(id));
                    }
                    baseWrapper.setMsg("ok");
                    baseWrapper.setFlag(true);
                    baseWrapper.setTime(new Date());
                    break;
                case 5:
                    for(String id:array){
                        fixFormMapper.deleteByExample(Integer.parseInt(id));
                    }
                    baseWrapper.setMsg("ok");
                    baseWrapper.setFlag(true);
                    baseWrapper.setTime(new Date());
                    break;
            }
        }
        return baseWrapper;
    }

    /**
     * @Author  高亚峰
     * @date    15:10 2018-1-18
     * @Desc    查询企业状态数量
     * @param
     **/
    public BaseWrapper getStatusCount(){
        BaseWrapper baseWrapper =new BaseWrapper();
        FixFormWithBLOBs fixFormWithBLOBs = fixFormMapper.selectCounts();
        String sum = fixFormWithBLOBs.getSum();
      int i = fixFormMapper.selectCountByState("01");
        int i2 = fixFormMapper.selectCountByState("02");
        int i3 = fixFormMapper.selectCountByState("03");
        Map<String,Object> resultMap =new HashedMap();
        resultMap.put("sum",Integer.valueOf(sum));
       resultMap.put("type01",i);
        resultMap.put("type02",i2);
        resultMap.put("type03",i3);
        baseWrapper.setMsg("ok");
        baseWrapper.setFlag(true);
        baseWrapper.setData(resultMap);
        baseWrapper.setTime(new Date());
        return baseWrapper;


    }
    public BaseWrapper getUserInfo(HttpServletRequest request){
        BaseWrapper baseWrapper=new BaseWrapper();
        Users user= SessionUtils.getSessionInfo(request.getSession(), Users.class,new Users());
        if(user!=null){
            baseWrapper.setData(user);
            baseWrapper.setFlag(true);
            baseWrapper.setMsg("ok");
        }
           return  baseWrapper;

    }

    public BaseWrapper selectUnionAllByName(HttpServletRequest request, String state, Integer page, Integer pageSize){
        BaseWrapper baseWrapper=new BaseWrapper();
        Map<String, Object> map=new HashMap<String, Object>();
        map.put("state",state);
        page = (page - 1) * pageSize;
        map.put("page",page);
        map.put("pageSize",pageSize);
        List<GeneralSafetyUnitWithBLOBs>  generalSafetyUnitWithBLOBs=  generalSafetyUnitMapper.selectUnionAllByName(map);
        for(GeneralSafetyUnitWithBLOBs gr:generalSafetyUnitWithBLOBs){
            if(!StringUtils.checkNull(gr.getEnterpriseState())){
                gr.setCodeName(sysCodeMapper.getSingleCode("enterprisestuts",gr.getEnterpriseState()).getCodeName());
            }

        }

        int total=generalSafetyUnitMapper.selectUnionAllByNameCount(state);
        baseWrapper.setMsg("ok");
        baseWrapper.setStatus(true);
        baseWrapper.setFlag(true);
        baseWrapper.setData(generalSafetyUnitWithBLOBs);
        baseWrapper.setTotle(total);
        return  baseWrapper;
    }
}
